using UnityEngine;
using System.Collections;

public class Rectangles  {
	public float x,y,width,height;
	public float right;
    public float bottom;
	
	public Rectangles (float xs,float ys,float w,float h)
	{
		x = xs;
		y = ys;
		width = w;
		height = h;
		right = x + width;
		bottom = y + height;
	}
	
	public Rectangles ()
	{
	}
	
	// Use this for initialization
	void Start () {

	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	public  void Updates()
	{
	right = x + width;
    bottom = y + height;		
	}
	
	public Rectangles CopyRectangles ()
    {
    	return new Rectangles(x, y, width, height);
	}
	
	
	public bool Intersects (Rectangles other)
    {        
        float iLeft = Mathf.Max(this.x, other.x);
        float iRight = Mathf.Min(this.right, other.right);
        float iTop = Mathf.Max(this.y, other.y);
        float iBottom = Mathf.Min(this.bottom, other.bottom);
        
        return (iRight > iLeft && iBottom > iTop);
    }
	
	public bool Contains (Rectangles other)
    {
        bool pointOne = false;
        bool pointTwo = false;
        bool pointThree = false;
        bool pointFour = false;
        
        if(other.x > this.x &&
           other.x < this.x + this.width &&
           other.y > this.y &&
           other.y < this.y + this.height) pointOne = true;
           
        if(other.x + other.width > this.x &&
           other.x + other.width < this.x + this.width &&
           other.y > this.y &&
           other.y < this.y + this.height) pointTwo = true;
           
                      
        if(other.x > this.x &&
           other.x < this.x + this.width &&
           other.y + other.height > this.y &&
           other.y + other.height < this.y + this.height) pointThree = true;  
                
           
        if(other.x + other.width > this.x &&
           other.x + other.width < this.x + this.width &&
           other.y + other.height > this.y &&
           other.y + other.height < this.y + this.height) pointFour = true;
           
           
        return pointOne && pointTwo && pointThree && pointFour;
    }
	
	public bool ContainsPoint (Rectangles other)
    {
        return (
            other.x > this.x &&
            other.x < this.x + this.width &&
            other.y > this.y &&
            other.y < this.y + this.height
            );
    }
}
